CREATE TRIGGER trig_meeting ON meeting
AFTER INSERT,UPDATE
AS
BEGIN
DECLARE @start_time INTEGER
DECLARE @end_time INTEGER  
DECLARE @section_id INTEGER
DECLARE @meeting_id INTEGER
DECLARE @weekday VARCHAR

SELECT @start_time = (SELECT start_time FROM inserted)
SELECT @end_time = (SELECT end_time FROM inserted)
SELECT @section_id = (SELECT section_id FROM inserted)
SELECT @meeting_id = (SELECT meeting_id FROM inserted)
SELECT @weekday = (SELECT weekday FROM inserted)

IF EXISTS (SELECT * FROM meeting WHERE meeting.section_id = @section_id 
						AND meeting.weekday = @weekday
						AND @end_time > start_time AND @start_time < end_time 
						AND NOT @meeting_id = meeting_id)
	BEGIN
		ROLLBACK TRANSACTION
		RAISERROR ('Sorry, Conflict meeting time.',12, 1)
	END
END
